home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / gnu / ms-0_06.lha / mslaved-0.06 / enslave < prev    next >
Text File  |  1991-08-10  |  2KB  |  83 lines

  1. #!/bin/sh
  2. #
  3. # enslave - manual startup of MandelSpawn computation servers
  4. # usage: enslave [-n] [-v] [hosts...]
  5. #
  6. #    -v means print the rsh commands before executing
  7. #     -n means print the rsh commands but don't execute them
  8. #
  9.  
  10. # If you are running System V where "rsh" means "restricted shell" by default,
  11. # you may need to change "rsh" below to "/usr/ucb/rsh", "/usr/bsd/rsh" or 
  12. # wherever the "remote shell" command resides on your particular system.
  13. RSH=rsh
  14.  
  15. while true
  16. do
  17.     case $1 in
  18.         -v) SHOPTS="${SHOPTS}v"; shift ;;
  19.         -n) SHOPTS="${SHOPTS}nv"; shift ;;
  20.         *) break ;;
  21.     esac
  22. done
  23.  
  24. tmp=/tmp/ens$$
  25. tmp3=/tmp/enu$$
  26.  
  27. sort -b $HOME/.enslave | grep -v '^#' >$tmp
  28.  
  29. # if arguments, extract the wanted machines
  30. if test -n "$*"
  31. then
  32.     tmp2=/tmp/ent$$
  33.     for mach in $*
  34.     do 
  35.         echo $mach
  36.     done | sort -b >$tmp2
  37.     cat $tmp | awk '{print $1}' | comm -13 - $tmp2 |
  38.            awk '{printf "'$0': host %s not in .enslave, ignored\n", $1}' 1>&2
  39.     join $tmp $tmp2
  40.     rm -f $tmp2
  41. else
  42.     cat $tmp
  43. fi >$tmp3
  44.  
  45. cat $tmp3 |
  46.   awk '
  47.   { opts=""
  48.      for(i=3; i<=NF; i++) opts=opts" "$i
  49.      printf "%s \"%s%s%s %s%s >/dev/null </dev/null &\"\n", \
  50.      $1, $2, "mslavedc", opts, $2, "mslaved" 
  51.   }' >$tmp
  52.  
  53. # If you have a different username on a remote machine and don't trust
  54. # it enough to put it in your .rhosts file, put it in .rhostile instead.
  55.  
  56. cat $HOME/.rhosts $HOME/.rhostile 2>/dev/null | sort -b | 
  57.   # if multiple usernames for the same host, chooses one arbitrarily
  58.   awk '{print $2, $1}' | uniq -1 | 
  59.   awk '{print $2, "-l", $1}' | join -a2 - $tmp | 
  60.  
  61. # Now the data stream contains ready-to-run rsh arguments.  Run the rsh's
  62. # in parallel, with some delay inbetween to avoid driving the load average
  63. # too high.  Because most of the possible error messages from the remote
  64. # process do not include the host name, prepend it to the output from rsh.
  65.  
  66. (
  67. while read host rest
  68. do
  69.     # the silly quoted newline is there just to get newlines in the output
  70.     # of "enslave -v" and "enslave -n".  The redirect from </dev/null
  71.     # is to stop rsh from eating the standard input stream intended
  72.     # for the "read" above.
  73.     sh -c$SHOPTS "exec $RSH $host $rest 2>&1 | sed -e 's/^/$host: /' 1>&2"'
  74. ' </dev/null &
  75.     sleep 2
  76. done 
  77.  
  78. wait    # make sure all error messages have been printed before exiting
  79. )
  80.  
  81. rm -f $tmp $tmp3
  82.